#include<bits/stdc++.h>
#define ll long long
#define mid ((l+r)>>1)
#define ls (x<<1)
#define rs ((x<<1)|1) 
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    void pc(const char *s){
    	while(*s)putch(*s),s++;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x),putch(' '),write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=1e5+5,M=6;
int n,m,q;
int c[N],a[N][M];
struct node{
	ll f[M][M];
	inline void Init(){
		memset(f,-0x3f,sizeof f);
		return;
	}
}tree[N<<2];
inline void update(int x){
	tree[x].Init();
	for(int i=0;i<=m;i++)
		for(int j=0;j<=m;j++)
			for(int k=0;k<=m;k++)
				tree[x].f[i][k]=max(tree[x].f[i][k],tree[ls].f[i][j]+tree[rs].f[j][k]);
	return;
}
void build(int x,int l,int r){
	if(l==r){
		tree[x].Init();
		for(int i=0;i<m;i++)tree[x].f[i][i]=a[l][i];
		tree[x].f[m][m]=tree[x].f[c[l]][m]=tree[x].f[m][c[l]]=a[l][c[l]];
		return;
	}
	build(ls,l,mid),build(rs,mid+1,r);
	update(x);
}
void modify(int x,int l,int r,int w){
	if(l==r){
		tree[x].Init();
		for(int i=0;i<m;i++)tree[x].f[i][i]=a[l][i];
		tree[x].f[m][m]=tree[x].f[c[l]][m]=tree[x].f[m][c[l]]=a[l][c[l]];
		return;
	}
	if(w<=mid)modify(ls,l,mid,w);
	else modify(rs,mid+1,r,w);
	update(x);
}
ll ans[M],tmp[M];
void query(int x,int l,int r,int L,int R){
	if(L<=l&&r<=R){
		memset(tmp,-0x3f,sizeof tmp);
		for(int i=0;i<=m;i++)
			for(int j=0;j<=m;j++)
				tmp[j]=max(tmp[j],ans[i]+tree[x].f[i][j]);
		swap(ans,tmp);
		return;
	}
	if(L<=mid)query(ls,l,mid,L,R);
	if(R>mid)query(rs,mid+1,r,L,R);
	return;
}
ll sol(int l,int r){
	if(l==r)return a[l][c[l]];
	memset(ans,-0x3f,sizeof ans);
	ans[c[l]]=ans[m]=a[l][c[l]];
	query(1,1,n,l+1,r);
	return ans[m];
}
signed main(){
	freopen("paint.in","r",stdin);
	freopen("paint.out","w",stdout);
	read(n,m,q);
	for(int i=1;i<=n;i++)read(c[i]),c[i]--;
	for(int i=1;i<=n;i++)
		for(int j=0;j<m;j++)
			read(a[i][j]);
	build(1,1,n);
	ll last_ans;
	write(last_ans=sol(1,n)),putch('\n');
	while(q--){
		ll ops,x,y;
		read(ops,x,y);
		x^=last_ans,y^=last_ans;
		if(ops==1){
			c[x]=y-1;
			modify(1,1,n,x);
		}else write(last_ans=sol(x,y)),putch('\n');
	}
	flush();
	return 0;
}
